/**
 * 
 */
package transitions;

import javax.swing.JOptionPane;

import org.salespointframework.core.Gate;
import org.salespointframework.core.SaleProcess;
import org.salespointframework.core.Transition;
import org.salespointframework.core.users.User;

import Processes.ProcessMyEvents;
import data.Appointment;
import data.Event;
import fsccs.AdministrateEventContentCreator;


/**
 * Diese Klasse beschreibt die Transition Tauschen eines Termins.
 * @author INF06
 * 
 */
public class SwitchEventDateTransition implements Transition {
	
	/** ContentCreator */
	AdministrateEventContentCreator me;
	
	/**
	 * Konstruktor
	 *
	 * @param me the me
	 */
	public SwitchEventDateTransition(AdministrateEventContentCreator me) {
		this.me=me;
		}


	/* (non-Javadoc)
	 * @see org.salespointframework.core.Transition#perform(org.salespointframework.core.SaleProcess, org.salespointframework.core.users.User)
	 */
	@Override
	public Gate perform(SaleProcess sp, User user) {
		int more = JOptionPane.showConfirmDialog(null, "Wollen Sie den Termin wirklich zum Tausch anbieten?", "Achtung",
                JOptionPane.YES_NO_OPTION);
		if (more==JOptionPane.NO_OPTION) return ((ProcessMyEvents)sp).getEditEvent(me.getEvent());
		Event event=me.getEvent();
		try {
			Appointment app=event.getAppsCat().getbyDate(me.getDate());
			app.setStatus(Appointment.STATUS_SWITCH);			
			JOptionPane.showMessageDialog(null,
				    "Termin wurde zum Tausch freigegeben.", 
				    "Information",JOptionPane.INFORMATION_MESSAGE);
			return ((ProcessMyEvents)sp).getEditEvent(me.getEvent());
			
			
		} catch (Exception e) {
			JOptionPane.showMessageDialog(null,
				    "Es ist ein interner Fehler aufgetreten."+e, 
				    "Achtung",JOptionPane.INFORMATION_MESSAGE);
		}
		return ((ProcessMyEvents)sp).getEditEvent(me.getEvent());
		
	}

}
